package com.dime.physical.controller;

import com.dime.physical.domain.DimePhysicalregister;
import com.dime.physical.domain.dto.DimeHistoryPhysicalDto;
import com.dime.physical.domain.dto.MaincheckViewDto;
import com.dime.physical.domain.dto.MainchecksubmitDto;
import com.dime.physical.domain.dto.SearchPhysicalregister;
import com.dime.physical.service.IDimeMainCheckService;
import com.dime.physical.service.IDimePhysicalregisterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/MainCheck")
public class DimeMainCheckController extends BaseController {

    @Autowired
    private IDimePhysicalregisterService dimePhysicalregisterService;


    @Autowired
    private IDimeMainCheckService dimeMainCheckService;


    //@RequiresPermissions("physical:MainCheck:list")
    @GetMapping("/list")
    public AjaxResult list(SearchPhysicalregister searchPhysicalregister) {

        List<DimePhysicalregister> list = dimePhysicalregisterService.searchMainCheckDimePhysicalregisterList(searchPhysicalregister);
        return success(list);
    }


  //  @RequiresPermissions("physical:MainCheck:getMainCheckByCheckcode")
    @PostMapping("/getMainCheckByCheckcode")
    public AjaxResult getMainCheckByCheckcode(@RequestBody DimePhysicalregister dimePhysicalregister) {


        if (Integer.parseInt(dimePhysicalregister.getCompletStatus())<1) {
            return error("该人员还在体检中..");
        }

        MaincheckViewDto maincheckDto = dimeMainCheckService.getMaincheckPhysical(dimePhysicalregister);

        return success(maincheckDto);
    }


    @RequiresPermissions("physical:MainCheck:SaveMaincheck")
    @PostMapping("/SaveMaincheck")
    public AjaxResult SaveMaincheck(@RequestBody MainchecksubmitDto mainchecksubmitDto) {


        if (!Objects.equals(mainchecksubmitDto.getCompletStatus(), "1")) {
            return error("该人员不是待主检状态！");
        }

        return toAjax(dimeMainCheckService.SaveMaincheck(mainchecksubmitDto));
    }


   // @RequiresPermissions("physical:MainCheck:RevokeMaincheck")
    @PostMapping("/RevokeMaincheck")
    public AjaxResult RevokeMaincheck(@RequestBody DimePhysicalregister dimePhysicalregister) {


        if(Integer.parseInt(dimePhysicalregister.getCompletStatus())<1)
        {
            return error("该人员主检未完成！");
        }

        return success(dimeMainCheckService.RevokeMaincheck(dimePhysicalregister));
    }


   // @RequiresPermissions("physical:MainCheck:getSubmitMaincheckPhysical")
    @PostMapping("/getSubmitMaincheckPhysical")
    public AjaxResult getSubmitMaincheckPhysical(@RequestBody DimePhysicalregister dimePhysicalregister) {

        if(Integer.parseInt(dimePhysicalregister.getCompletStatus())<1)
        {
            return success("该人员主检未完成！");
        }

        MainchecksubmitDto mainchecksubmitDto = dimeMainCheckService.getSubmitMaincheckPhysical(dimePhysicalregister);

        return success(mainchecksubmitDto);
    }



    @PostMapping("/getHistoryPhysical")
    public AjaxResult getHistoryPhysical(@RequestBody DimePhysicalregister dimePhysicalregister) {

        List<DimeHistoryPhysicalDto> dimeHistoryPhysicalDto=dimeMainCheckService.getHistoryPhysical(dimePhysicalregister);
        return success(dimeHistoryPhysicalDto);
    }


}
